const fs = require("fs")
const path = require("path")

// "D:/就业辅导"

/* 对象形式输出文件夹中的文件信息 */
function listDir(dirPath) {
    const files = []

    const fpaths = fs.readdirSync(dirPath)
    fpaths.forEach(
        (name) => {

            const fpath = path.join(dirPath, name)
            const isDirectory = fs.statSync(fpath).isDirectory()
            console.log(fpath, isDirectory);

            if (isDirectory) {
                files.push(listDir(fpath))
            }

            files.push(name)
        }
    )

    return {
        dirPath,
        files
    }
}

/* 输出内容到指定文件 */
function content2File(content, path) {
    fs.writeFileSync(path, content)
    console.log("输出完成！");
}

content2File(
    JSON.stringify(listDir("D:/就业辅导")),
    "./out.json"
)

listDir("E:/乔布梭的前端课_20230105/就业辅导-闲聊版")

